function varargout = anncyclog (s, ps, pp)

   ## usage:  varargout = anncyclog (s, ps, pp)
   ##
   ## remove annual cycle from log of data, and normalize

   global PAR

   r = s ;
   rm = repmat(mean(r.x)*PAR.Pzero, rows(r.x), 1) ;
   r.x(r.x < rm) = 0 ;
   r.x = log(r.x) ;
   if (nargin > 1)
      r = anncyc(r, ps) ;
   else
      [ps r] = anncyc(r) ;
   endif 
   r.a = r.a + repmat(ps(1,:), rows(r.a), 1) ; # remove harmonics, leave mean
   r.a = exp(r.a) ;
   r.x = s.x ;

   if (nargin > 2)
      dbg = PAR.dbg ; PAR.dbg = false ;
      r.z = normprc(r.a, pp) ;
      PAR.dbg = dbg ;
   else
      [pp, r.z] = normprc(r.a) ;
   endif 

   if (nargin == 1)
      if (nargout > 1)
	 varargout{1} = ps ;
	 varargout{2} = pp ;
	 if (nargout > 2)
	    varargout{3} = r ;
	 endif 
      endif 
   else
      varargout{1} = r ;
   endif 

endfunction
